﻿/*
(c) 2010 - Open Source Business Foundation e. V. (www.osbf.de)
This software is provided under Microsoft Reciprocal License (Ms-RL)
(http://www.microsoft.com/opensource/licenses.mspx#Ms-RL)
All other rights reserved
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using MicroFormatProcessing;

namespace MicroFormatWebRole
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                StatusSection.Visible = false;
            }
        }

        protected void OnLoginButtonClick(object sender, EventArgs e)
        {
            string userName = UsernameTextbox.Text;
            string password = PasswordTextbox.Text;
            if ((userName != null) && (password != null))
            {
                switch (UserUtil.CheckUser(userName, password))
                {
                    case UserUtil.OK:
                        Session session = UserUtil.CreateSession(userName);
                        Response.Cookies["session"]["id"] = session.GetSessionId();
                        StringBuilder url = new StringBuilder();
                        url.Append("Browse.aspx?user=").Append(userName);
                        Response.Redirect(url.ToString());
                        break;
                    case UserUtil.UNKNOWN_USER:
                        StatusLabel.Text = "Unknown User!";
                        StatusSection.Visible = true;
                        break;
                    case UserUtil.WRONG_PASSWORD:
                        StatusLabel.Text = "Wrong Password!";
                        StatusSection.Visible = true;
                        break;
                }
            }
        }
    }
}